<template>
    <div class="container2">
      <Nav></Nav>
      <div class="swiper-container">
        <div class="swiper-wrapper">
          <div class="swiper-slide" v-for="(item,index) in swiperimg" :key="index">
            <img :src="item" alt="">
          </div>
        </div>
        <!-- Add Pagination -->
        <div class="swiper-pagination"></div>
      </div>
      <div class="con-d1">
        <span>资讯动态</span>
        <span @click="more()">更多资讯 <img :src="'./static/lyl/youjian.png'" alt=""></span>
      </div>
      <ul class="ulone">
        <li @click="deta(item)" v-for="(item,index) in datatx" :key="index">
          <div class="li-left">
            <p>{{item.post_title}}</p>
            <div class="li-footer">
              <span>{{item.user_login}}</span>
              <span>{{item.post_date}}</span>
            </div>
          </div>
          <img :src="item.smeta" alt="">
        </li>
      </ul>
      <div class="s_box">
        <p>舞会活动</p>
        <ul class="ultwo">
          <li @click="actdet(item)" v-for="(item,index) in dataty" :key="index">
            <div class="li-top">
              <img :src="item.main_pic" alt="">
              <span>{{item.apply}}</span>
              <span v-if="item.is_rec==0?false:true">推荐</span>
            </div>
            <p>{{item.title}}</p>
          </li>
        </ul>
        <p>
          <span>舞会</span>
          <span @click="party()">查看更多 <img src="../../../assets/img/youjian.png" alt=""></span>
        </p>
      </div>

      <!--<div class="s_box">-->
        <!--<p>推荐课程</p>-->
        <!--<ul class="ke_ul">-->
          <!--<li v-for="(item,index) in courseData" :key="index">-->
            <!--<div class="left">-->
              <!--<img :src="item.thumb" alt="">-->
              <!--<span>{{item.title}}</span>-->
            <!--</div>-->
            <!--<div class="right">-->
              <!--<p>{{item.tit}}</p>-->
              <!--<p>-->
                <!--<span>{{item.mon}}</span>-->
                <!--<span>{{item.isNo}}</span>-->
              <!--</p>-->
              <!--<p>-->
                <!--<span>{{item.anmin}}</span>-->
                <!--<span>{{item.num}}已购买</span>-->
              <!--</p>-->
            <!--</div>-->
          <!--</li>-->
        <!--</ul>-->
        <!--<p>-->
          <!--<span>学院课程</span>-->
          <!--<span @click="kec()">查看更多 <img src="../../../assets/img/youjian.png" alt=""></span>-->
        <!--</p>-->
      <!--</div>-->

      <div class="s_box">
        <p>推荐机构</p>
        <ul class="ji_ul">
          <li @click="menav(item)" v-for="(item,index) in orgData" :key="index">
            <div class="top">
              <img :src="item.avatar" alt="数据加载失败">
              <!--<span>888人已加入学习</span>-->
            </div>
            <div class="bottom">
              <p>{{item.user_login}}</p>
              <p>{{item.signature}}</p>
            </div>
          </li>
        </ul>
        <p>
          <span>机构</span>
          <span @click="jiM()">查看更多 <img src="../../../assets/img/youjian.png" alt=""></span>
        </p>
      </div>
      <div class="s_box">
        <p>推荐达人</p>
        <ul class="da_ul">
          <li v-for="(item,index) in expData" :key="index">
            <img @click="menav(item)" :src="item.avatar" alt="数据加载失败">
            <div @click="menav(item)" class="e_center">
              <p>{{item.user_login}}</p>
              <p>{{item.signature}}</p>
              <p>领域：{{item.territory}}</p>
            </div>
            <span @click="follow(item)">{{item.status==0?'+ 关注':'已关注'}}</span>
          </li>
        </ul>
        <p>
          <span>达人</span>
          <span @click="moreP()">查看更多 <img src="../../../assets/img/youjian.png" alt=""></span>
        </p>
      </div>

      <transition name="van-slide-right">
        <div v-show="visible" class="tran_right">{{Fade}}</div>
      </transition>

      <Footer></Footer>
    </div>
</template>

<script>
  import Swiper from 'swiper'
  import Nav from '../../com/Nav'
  import Footer from '../../com/Footer'
  import * as home from "../../../api/home.js"
  import * as search from "../../../api/search.js"

  // import axios from 'axios'
    export default {
      name: "Home",
      data(){
        return {
          Fade:'',
          visible:false,
          datatx:[],
          dataty:[],
          swiperimg:[],
          // courseData:[
          //   {thumb:require("../../../assets/img/2.jpg"),title:'音频',tit:'芭蕾舞的天下你知不知',mon:'免费',isNo:'已购买',anmin:'用户昵称',num:'12'},
          //   {thumb:require("../../../assets/img/2.jpg"),title:'视频',tit:'芭蕾舞的天下你知不知',mon:'免费',isNo:'已购买',anmin:'用户昵称',num:'12'},
          //   {thumb:require("../../../assets/img/2.jpg"),title:'专栏',tit:'芭蕾舞的天下你知不知',mon:'免费',isNo:'已购买',anmin:'用户昵称',num:'12'},
          //   {thumb:require("../../../assets/img/2.jpg"),title:'线下',tit:'芭蕾舞的天下你知不知',mon:'免费',isNo:'已购买',anmin:'用户昵称',num:'12'}
          // ],
          orgData:[],
          expData:[]
        }
      },
      components:{
        Nav,
        Footer
      },
      beforeMount(){
        let parmes = {type:1};
        home.bannerList(parmes).then(res=>{
          this.swiperimg = res.data;
          this.$nextTick(() => {  // 下一个UI帧再初始化swiper
            var swiper = new Swiper('.swiper-container', {
              autoplay:true,
              loop : true,
              pagination: {
                el: '.swiper-pagination',
              },
            });
          })
        });

        home.postsList(parmes).then(res=>{
          this.datatx = res.data;
        });

        home.activeList(parmes).then(res=>{
          this.dataty = res.data;
        });

        //推荐机构
        let parms2 = {user_type:2,page:1,per_page:4,user_id:this.$store.state.user_id};
        search.recommendUser(parms2).then(res=>{
          console.log('推荐机构',res)
          this.orgData = res.data;
        });

        //推荐达人
        let parms3 = {user_type:1,page:1,per_page:4,user_id:this.$store.state.user_id};
        search.recommendUser(parms3).then(res=>{
          this.expData = res.data;
          console.log('推荐达人',res)
        });

      },
      mounted(){
        // //首页返回键处理
        // //处理逻辑：1秒内，连续两次按返回键，则退出应用；
        var first = null;
        mui.back = function() {
          //首次按键，提示  再按一次退出应用
          if (!first) {
            first = new Date().getTime();//记录第一次按下回退键的时间
            mui.toast('再按一次退出大集舞会');//给出提示
            history.go(-1)//回退到上一页面
            setTimeout(function() {//1s中后清除
              first = null;
            }, 1000);
          } else {
            if (new Date().getTime() - first < 1000) {//如果两次按下的时间小于1s，
              plus.runtime.quit();//那么就退出app

            } } };
      },
      methods:{
        party(){
          this.$router.push("/ball/1")
        },
        // kec(){
        //   this.$router.push("/course/2")
        // },
        jiM(){
          this.$router.push("/moreorgan")
        },
        moreP(){
          this.$router.push("/moreperson")
        },
        more(){
          this.$router.push({ path: "/morenews" });
        },
        deta(item){
          this.$router.push({path:'/detail/'+item.id});
        },
        actdet(item){
          this.$router.push({path:'/active2/0/'+item.id});
        },
        follow(item){
          if (item.status==0){
            item.status = 1;
            let flow = {follow_id:item.id,user_id:this.$store.state.user_id,status:1};
            search.follow(flow).then(res=>{
              console.log(res);
              this.visible = true;
              this.Fade = res.msg;
              setTimeout(() => {
                this.visible = false;
              }, 500);
            });
            search.followed(flow).then(res=>{
              console.log(res);
            })
          } else{
            item.status = 0;
            let flow = {follow_id:item.id,user_id:this.$store.state.user_id,status:0};
            search.follow(flow).then(res=>{
              console.log(res);
              this.visible = true;
              this.Fade = res.msg;
              setTimeout(() => {
                this.visible = false;
              }, 500);
            });
            search.followed(flow).then(res=>{
              console.log(res);
            })
          }
        },
        menav(item){
          this.$router.push({
            path: '/menav',
            query:{
              id:item.id
            }
          })
        }
      }
    }
</script>

<style>
  .container2{
    padding:100px 0 158px;
  }
  .swiper-container {
    width: 100%;
  }
  .swiper-slide {
    text-align: center;
    font-size: 18px;
    background: #fff;

    /* Center slide text vertically */
    display: -webkit-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    -webkit-justify-content: center;
    justify-content: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    -webkit-align-items: center;
    align-items: center;
  }
  .swiper-slide img{
    width: 100%;
    height: 400px;
  }
  .swiper-container-horizontal>.swiper-pagination span.swiper-pagination-bullet{
    width: 20px;
    height: 20px;
    border-radius: 100%;
    background: #fff;
    opacity: 1;
    filter:alpha(opacity=100);
    margin: 0 16px;
  }
  .swiper-container-horizontal>.swiper-pagination span.swiper-pagination-bullet-active{
    background: #a966ec;
  }
  .con-d1{
    display: flex;
    justify-content: space-between;
    padding: 20px 40px;
  }
  .con-d1 span:nth-child(1){
    font-size: 32px;
  }
  .con-d1 span:nth-child(2){
    font-size: 26px;
  }
  .con-d1 span:nth-child(2) img{
    width: 11px;
  }
  .ulone li{
    display: flex;
    justify-content: space-between;
    padding: 0 40px;
    margin-bottom: 30px;
  }
  .ulone li .li-left{
    width: 390px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;

  }
  .ulone li .li-left p{
    font-size: 28px;
    line-height: 44px;
  }
  .ulone li .li-left .li-footer span:nth-child(1){
    font-size: 24px;
    color: #558ef7;
  }
  .ulone li .li-left .li-footer span:nth-child(2){
    font-size: 22px;
    color: #8c8c8c;
    margin-left: 20px;
  }
  .ulone li img{
    width: 240px;
    height: 150px;
    border-radius: 10px;
  }
  .s_box{
    border-bottom: 2px solid #dcdcdc;
  }
  .s_box>p:nth-child(1){
    font-size: 32px;
    padding:20px 40px 0;
  }
  .s_box>p:last-child{
    display: flex;
    justify-content: space-between;
    font-size: 24px;
    padding:0 40px 20px;
  }
  .s_box p:last-child img{
    height: 20px;
  }
  .ultwo{
    padding: 20px 40px;
  }
  .ultwo li{
    position: relative;
    border-radius: 20px;
    background: #e7c7fd;
    overflow: hidden;
  }
  .ultwo li .li-top{
    position: relative;
    height: 400px;
    overflow: hidden;
  }
  .ultwo li .li-top img{
    width: 100%;
    height: 100%;
  }
  .ultwo li .li-top span{
    position: absolute;
    left: 20px;
    top: 20px;
    display: inline-block;
    cursor: pointer;
  }
  .ultwo li .li-top span:nth-child(2){
    position: absolute;
    right: 20px;
    top: 20px;
    width: 90px;
    height: 40px;
    border-radius: 20px;
    text-align: center;
    line-height: 40px;
    background: #ff6174;
    color: #fff;
  }
  .ultwo li .li-top span:nth-child(3){
    width: 52px;
    height: 63px;
    background: url("/static/lyl/recom.png") no-repeat center/cover;
    font-size: 24px;
    color: #fff;
    float: right;
    text-align: center;
  }
  .ultwo li p{
    position: absolute;
    left: 0;
    bottom: 0;
    box-sizing: border-box;
    width: 100%;
    font-size: 24px;
    color: #fff;
    padding: 13px 0 10px 20px;
    background: rgba(0,0,0,0.7);
  }

  /*.ke_ul{*/
    /*padding: 30px 40px;*/
  /*}*/
  /*.ke_ul li{*/
    /*display: flex;*/
    /*padding-bottom: 30px;*/
  /*}*/
  /*.ke_ul li .left{*/
    /*position: relative;*/
    /*margin-right: 25px;*/
  /*}*/
  /*.ke_ul li .left img{*/
    /*width: 250px;*/
    /*height: 150px;*/
    /*border-radius: 15px;*/
  /*}*/
  /*.ke_ul li .left span{*/
    /*border-radius: 5px;*/
    /*position: absolute;*/
    /*left: 10px;*/
    /*top: 10px;*/
    /*width: 66px;*/
    /*height: 30px;*/
    /*font-size: 24px;*/
    /*line-height: 30px;*/
    /*text-align: center;*/
    /*color: #fff;*/
    /*background: #884ca4;*/
  /*}*/
  /*.ke_ul li .right{*/
    /*display: flex;*/
    /*flex-direction: column;*/
    /*justify-content: space-between;*/
    /*flex-grow: 1;*/
  /*}*/
  /*.ke_ul li .right p:nth-child(1){*/
    /*font-size: 28px;*/
    /*font-weight: bolder;*/
    /*letter-spacing:5px;*/
  /*}*/
  /*.ke_ul li .right p:nth-child(2){*/
    /*display: flex;*/
    /*justify-content: space-between;*/
  /*}*/
  /*.ke_ul li .right p:nth-child(2) span:nth-child(1){*/
    /*font-size: 26px;*/
    /*color: #8c8c8c;*/
  /*}*/
  /*.ke_ul li .right p:nth-child(2) span:nth-child(2){*/
    /*font-size: 26px;*/
    /*color: #884ca4;*/
  /*}*/
  /*.ke_ul li .right p:nth-child(3){*/
    /*display: flex;*/
    /*justify-content: space-between;*/
  /*}*/
  /*.ke_ul li .right p:nth-child(3) span{*/
    /*font-size: 28px;*/
  /*}*/

  .ji_ul{
    padding: 30px 40px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .ji_ul li{
    width: 47%;
    padding-bottom: 30px;
  }
  .ji_ul li .top{
    height: 180px;
    background: #dcdcdc;
  }
  /*.ji_ul li .top{*/
    /*position: relative;*/
  /*}*/
  .ji_ul li .top img{
    width: 100%;
    height: 180px;
  }
  /*.ji_ul li .top span{*/
    /*position: absolute;*/
    /*bottom: 10px;*/
    /*left: 10px;*/
    /*font-size: 24px;*/
    /*color: #fff;*/
  /*}*/
  .ji_ul li .bottom p:nth-child(1){
    font-size: 28px;
    line-height: 36px;
  }
  .ji_ul li .bottom p:nth-child(2){
    font-size: 24px;
    line-height: 36px;
    color: #8c8c8c;
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
  }

  .da_ul li{
    display: flex;
    justify-content: space-between;
    padding: 20px 40px;
    border-bottom: 2px solid #dcdcdc;
  }
  .da_ul li:last-child{
    border-bottom: none;
  }
  .da_ul li img{
    background: #dcdcdc;
    width: 130px;
    height: 130px;
    border-radius: 50%;
  }
  .da_ul li .e_center{
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 55%;
  }
  .da_ul li .e_center p{
    font-size: 32px;
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
  }
  .da_ul li .e_center p:nth-child(2){
    font-size: 24px;
  }
  .da_ul li>span{
    width: 120px;
    height: 50px;
    line-height: 50px;
    text-align: center;
    border-radius: 10px;
    border: 2px solid #884ca4;
    color: #884ca4;
    font-size: 24px;
  }
  .tran_right{
    width: 220px;
    height: 60px;
    border-radius: 10px;
    text-align: center;
    line-height: 60px;
    font-size: 30px;
    top: 50%;
    left: 50%;
    position: fixed;
    background: rgba(0,0,0,0.6);
    color: #fff;
  }
</style>
